<template>

  <div class="admin-body">
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item >平台统计</el-breadcrumb-item>
        <el-breadcrumb-item>Ktv商家</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    <el-row style="padding: 15px">
      <el-row class="main">
        <!--顶部-->
        <el-row style="padding-bottom: 10px;text-align: left">
          <el-input placeholder="名称" v-model="selectkey" class="input-with-select" style="width: 200px">
          </el-input>
          <el-button type="primary" @click="getStart()">搜索</el-button>

          <el-date-picker
            v-model="dateValue"
            @change="getStart()"
            value-format="timestamp"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
          <div style="float: right">
            <el-button type="success" icon="el-icon-edit-outline" @click="exportExcel()">导出月收入统计</el-button>
            <el-button type="success" icon="el-icon-edit-outline" @click="exportExcelCZ()">导出扫码并充值用户详情</el-button>
          </div>
        </el-row>
        <!--表格-->
        <el-table
          border
          align="left"
          :data="tableData"
          style="width: 100%">
          <el-table-column
            type="selection"
            fixed="left"
            width="35">
          </el-table-column>
          <el-table-column
            prop="name"
            label="	店铺名称">
          </el-table-column>
          <el-table-column
            prop="address"
            label="	店铺地址">
          </el-table-column>
          <el-table-column
            prop="phone"
            label="	店铺联系电话">
          </el-table-column>
          <el-table-column
            label="	营业执照">
            <template slot-scope="scope">
              <el-popover
                v-if="scope.row.license"
                placement="bottom"
                trigger="hover">
                <div style="height: 300px;overflow-y: auto">
                  <img v-for="i in scope.row.license.split(',')" :src="i" alt="" width="300px" style="display: block">
                </div>
                <!--<el-button slot="reference" size="small" type="text">查看图片</el-button>-->
                <img slot="reference" :src="scope.row.license.split(',')[0]" alt="" width="60px" height="60px">
              </el-popover>
              <span v-if="!scope.row.license">无</span>
            </template>
          </el-table-column>
          <el-table-column
            label="创建时间">
            <template slot-scope="scope">
              {{toDate(scope.row.addtime)}}
            </template>
          </el-table-column>
          <el-table-column
            label="月结状态">
            <template slot-scope="scope">
              {{scope.row.end_state==1?'已月结':'未月结'}}
            </template>
          </el-table-column>
          <el-table-column
            label="月收入统计">
            <template slot-scope="scope">
              <el-button @click=" goHrefS ('agentIncome','incomeData',{id:scope.row.shop_id,apiM:'monthlyProfitS',apiD:'dayIncomeDetailsS',apiS:'editEndStateS'})">查看</el-button>
            </template>
          </el-table-column>
          <el-table-column
            label="扫码并充值用户详情">
            <template slot-scope="scope">
              <el-button  @click=" goHrefS ('agentCharge','chargeData',{type:2,id:scope.row.shop_id,api:'rechargeListS',apiT:'statisticsS'})">查看</el-button>
            </template>
          </el-table-column>
        </el-table>

        <!--分页-->
        <el-col :span="24" style="margin-top: 15px">
          <el-pagination
            style="text-align: right"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="dataTotal">
          </el-pagination>
        </el-col>
      </el-row>
    </el-row>

    <excel-dao-chu ref="excel"   :my-data="excelData" :my-name="excelName"  :my-title-obj="excelTitleData"></excel-dao-chu>

  </div>
</template>

<script>
  import MyUpload from '../../components/MyUpload'
  import ExcelDaoChu from '../../components/ExcelDaoChu'


  export default {
    name: "StatisticsShop",
    components: {
      MyUpload,
      ExcelDaoChu
    },
    mounted() {
      if (!this.$store.state.login.in) {
        this.$router.push({name: "login", params: {userId: 123}})
      }
      this.getStart()
    },
    data() {
      return {
        tableData: [],
        pageSize: 10,
        currentPage: 1,
        selectkey: '',
        dataTotal: 0,
        multipleSelection: [],
        formLabelWidth: '100px',
        dateValue:[
          (new Date(new Date(new Date().toLocaleDateString()).getTime())-1000 * 60 * 60 * 24*(new Date().getDate()-1)),
          new Date()
        ],
        excelData:[],
        excelTitleData:{},
        excelName:''
      }
    },
    computed: {
      account(){
        return this.$store.state.login.account
      },

    },
    methods: {
      // 获取数据
      getStart() {
        let thi = this
        const por = {
          page: thi.currentPage,
          pageSize: thi.pageSize,
          key: thi.selectkey,
          start_time:~~(thi.dateValue[0]/1000),
          over_time:~~(thi.dateValue[1]/1000)
        }
        thi.mySelectAll('reapShopList', por).then(function (value) {
          thi.tableData = value.data
          thi.dataTotal = value.Total
        })
      },
      // Excel导出
      exportExcel(){
        let thi= this
        const por={
          start_time:~~(thi.dateValue[0]/1000),
          over_time:~~(thi.dateValue[1]/1000),
        }
        thi.mySelect('exportDayIncomeDetailsS',por).then(function (data) {
          thi.excelData=data
          thi.excelTitleData={date:'日期',sum_money:'获得金额',sum_number:'推广人数',name:'店铺姓名',end_state:'完结状态'}
          thi.excelName='月收入统计'
          thi.$refs.excel.sureExcel()
        })
      },
      // Excel导出
      exportExcelCZ(){
        let thi= this
        const por={
          start_time:~~(thi.dateValue[0]/1000),
          over_time:~~(thi.dateValue[1]/1000),
        }
        thi.mySelect('exportScanAndRechargeListS',por).then(function (data) {
          thi.excelData=data
          thi.excelTitleData={orderno:'订单号',price:'充值金额',pay_time:'充值时间',nickname:'用户昵称',phone:'用户手机号',sum_number:'推广总人数',sum_money:'充值总金额'}
          thi.excelName='扫码并充值用户信息'
          thi.$refs.excel.sureExcel()
        })
      },
      //选择展示数量
      handleSizeChange(val) {
        this.pageSize = val
        this.getStart()
      },
      //跳转页面
      handleCurrentChange(val) {
        this.currentPage = val
        this.getStart()
      },
    }
  }
</script>

<style scoped>
  .admin-body {
    width: 100%;
  }

  .main {
    background-color: white;
    min-height: 500px;
    padding: 10px;
    border: #EDEDED 1px solid;
    border-radius: 5px;
  }
</style>
